package com.dk.controller;

import com.dk.pojo.TabCategory;
import com.dk.service.TabCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tabCategory")
public class TabCategoryController {

    @Autowired
    private TabCategoryService tabCategoryService;

    @RequestMapping("toShow")
    public String toShow(){
        return "category/show";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<TabCategory> getInfo(){
        List<TabCategory> result = tabCategoryService.getInfo();
        return result;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "category/add";
    }
    @RequestMapping("increase")
    @ResponseBody
    public boolean insertInfo(TabCategory tabCategory){
        return tabCategoryService.insert(tabCategory) > 0;
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id")Integer cid, Model model){
       TabCategory category = tabCategoryService.selectById(cid);
       model.addAttribute("category",category);
        return "category/update";
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TabCategory tabCategory){
        return tabCategoryService.updateInfo(tabCategory) > 0;
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer cid){
        return tabCategoryService.deleteById(cid) > 0;
    }

}
